package 题目集.贪心.排序模拟;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.PriorityQueue;
/**
 * 思路，优先队列存下标
 * https://www.acwing.com/problem/content/description/4964/
 */
public class F删除序列 {
    static long[] arr;
    static boolean[] del;   //是否被删除
    static int n, k;
    static int maxN = 5 * (int) (1e5)+1;
    static int[][] index=new int[maxN][2];  //记录每个位置的左侧和右侧

    public static void main(String[] args) {
       Reader sc = new Reader();
        n = sc.nextInt();
        k = sc.nextInt();
        arr = new long[n];
        del = new boolean[n];
        //0值，1下标
        PriorityQueue<long[]> queue = new PriorityQueue<>((a, b) -> {
            if (a[0] < b[0]) {
                return -1;
            } else if (a[0] > b[0]) {
                return 1;
            }
            return (int) (a[1] - b[1]);
        });
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
            index[i][0]=i-1;
            index[i][1]=i+1;
            queue.add(new long[]{arr[i], i});
        }
        for (int i = 0; i < k; i++) {
            long[] poll = queue.poll();
            while (del[(int) poll[1]] || poll[0] != arr[(int) poll[1]]) {    //被删除或被修改
                poll = queue.poll();
            }
            int id = (int) poll[1];
            int l = index[id][0];
            int r =index[id][1];
            del[id] = true;
            if (l != -1 && !del[l]) {
                arr[l]+=poll[0];
                index[l][1]=r;
                queue.add(new long[]{ arr[l],l});
            }
            if (r < n && !del[r]) {
                arr[r] += poll[0];
                index[r][0]=l;
                queue.add(new long[]{arr[r], r});
            }
        }
        for (int i = 0; i < del.length; i++) {
            if (!del[i]) {
                System.out.print(arr[i] + " ");
            }
        }
        System.out.println();
    }
    static class Reader {
        static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public static int nextInt() {
            try {
                in.nextToken();
            } catch (Exception ignored) {}
            return (int) in.nval;
        }
    }
}
